home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
st80_pr4.lha
/
st80_pre4
/
Foible
/
SDS
/
SDS-Tables.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
7KB
|
256 lines
Model subclass: #Table
instanceVariableNames: 'orderedValues startIndex stopIndex delta indexWholeDigit indexFractionDigit valueWholeDigit valueFractionDigit indexTitle valueTitle tableOC currentSelection '
classVariableNames: ''
poolDictionaries: ''
category: 'SDS-Tables'!
Table comment:
'This is a model for TableView. This class is used to create a table or
ordered values.
Instance Variables:
orderedValues <OrderedCollection>
the list of values to be presented in the table
startIndex <Float>
starting index for the table
stopIndex <Float>
the last index for the table
delta <Float>
index increment
indexWholeDigit <Number>
the number of whole digits in index column
indexFractionDigit <Number>
the number of fraction digits in index column
valueWholeDigit <Number>
the number of whole digits in value column
valueFractionDigit <Number>
the number of fraction digits in value column
indexTitle <Symbol>
the title for the index
valueTitle <Symbol>
the title for values
tableOC <OrderedCollection>
the table is presented in SelectionInListView
currentSelection <Symbol>
used for current selection in SelectionInListView '!
!Table methodsFor: 'private'!
findFractionDigitLength: aFloat
| aStream |
aStream _ TextStream on: ''.
aFloat abs fractionPart printOn: aStream.
^aStream contents asString size - 2!
findWholeDigitLength: aFloat
| aStream |
aStream _ TextStream on: ''.
aFloat truncated printOn: aStream.
^aStream contents asString size!
printFloat: aFloat withWholeDigitLength: aWholeDigitLength fractionDigitLength: aFractionDigitLength
| aStream aByteString counter size tempString wholeLength fractionLength|
(wholeLength _ self findWholeDigitLength: aFloat)
> aWholeDigitLength
ifTrue:
[aStream _ TextStream on: ''.
aFloat printOn: aStream.
^aStream contents asString].
size _ aWholeDigitLength + aFractionDigitLength + 1.
aByteString _ ByteString new: size.
counter _ 1.
[counter <=aWholeDigitLength] whileTrue: [aByteString at: counter put: Character space. counter _ counter + 1].
[counter <= size] whileTrue: [aByteString at: counter put: $0.counter _ counter + 1].
aByteString at: aWholeDigitLength + 1 put: $. .
aStream _ TextStream on: ''.
aFloat truncated printOn: aStream.
tempString _ aStream contents asString.
aByteString replaceFrom: (aWholeDigitLength + 1 - wholeLength) to: (aWholeDigitLength) with: tempString startingAt: 1.
aStream _ TextStream on: ''.
(fractionLength _ self findFractionDigitLength: aFloat) >aFractionDigitLength ifTrue: [fractionLength _ aFractionDigitLength] .
aFloat abs fractionPart printOn: aStream.
tempString _ aStream contents asString.
aByteString replaceFrom: (aWholeDigitLength + 2) to: (aWholeDigitLength + 1 + fractionLength) with: tempString startingAt: 3.
^aByteString.!
printTitle: aSymbol withStringLength: aNumber
| aByteString counter |
aByteString _ ByteString new: aNumber.
counter _ 1.
[counter <= aNumber]
whileTrue:
[aByteString at: counter put: Character space.
counter _ counter + 1].
aSymbol size >= aNumber ifTrue: [^aSymbol asString].
aByteString
replaceFrom: aNumber - aSymbol size // 2 + 1
to: aNumber - aSymbol size // 2 + aSymbol size
with: aSymbol asString
startingAt: 1.
^aByteString!
setIndexLengths
| temp |
indexFractionDigit _ self findFractionDigitLength: delta.
(temp _ self findWholeDigitLength: startIndex) > (indexWholeDigit _ self findWholeDigitLength: stopIndex) ifTrue: [indexWholeDigit _ temp]!
setValueLengths
| temp |
valueFractionDigit _ 0.
valueWholeDigit _ 1.
orderedValues do:
[:value |
(temp _ self findFractionDigitLength: value asFloat) > valueFractionDigit ifTrue: [valueFractionDigit _ temp].
(temp _ self findWholeDigitLength: value asFloat) > valueWholeDigit ifTrue: [valueWholeDigit _ temp]].
valueFractionDigit > 3 ifTrue: [valueFractionDigit _ 3]! !
!Table methodsFor: 'creating'!
buildTable
| aString tempIndex counter |
self setIndexLengths.
self setValueLengths.
aString _ (self printTitle: indexTitle withStringLength: indexFractionDigit + indexWholeDigit + 1)
, ' ' , (self printTitle: valueTitle withStringLength: valueWholeDigit + valueFractionDigit + 1).
tableOC _ OrderedCollection new.
tableOC add: aString asSymbol.
tempIndex _ startIndex.
counter _ 1.
[tempIndex <= stopIndex]
whileTrue:
[aString _ self
printFloat: tempIndex
withWholeDigitLength: indexWholeDigit
fractionDigitLength: indexFractionDigit.
aString _ aString , ' ' , (self
printFloat: ((orderedValues at: counter) asFloat)
withWholeDigitLength: valueWholeDigit
fractionDigitLength: valueFractionDigit).
tableOC add: aString asSymbol.
counter _ counter + 1.
tempIndex _ tempIndex + delta]! !
!Table methodsFor: 'accessing'!
currentSelection
^currentSelection!
currentSelection: aSymbol
^currentSelection _ aSymbol!
delta
^delta!
delta: aNumber
^delta _ aNumber!
indexTitle
^indexTitle!
indexTitle: aSymbol
^indexTitle _ aSymbol!
menu
^nil!
orderedValues
^orderedValues!
orderedValues: anOrderedCollection
^orderedValues _ anOrderedCollection!
startIndex
^startIndex!
startIndex: aNumber
^startIndex _ aNumber!
stopIndex
^stopIndex!
stopIndex: aNumber
^stopIndex _ aNumber!
tableOC
^tableOC!
tableOC: anOrderedCollection
^tableOC_ anOrderedCollection!
valueTitle
^valueTitle!
valueTitle: aSymbol
^valueTitle _ aSymbol! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
Table class
instanceVariableNames: ''!
!Table class methodsFor: 'instance creation'!
withStartIndex: aStartIndex stopIndex: aStopIndex delta: aDelta orderedValues: anOrderedValues indexTitle: anIndexTitle valueTitle: aValueTitle
|aTable|
aTable _ Table new.
aTable startIndex: aStartIndex asFloat.
aTable stopIndex: aStopIndex asFloat.
aTable delta: aDelta asFloat.
aTable orderedValues: anOrderedValues.
aTable indexTitle: anIndexTitle.
aTable valueTitle: aValueTitle.
^aTable.! !
View subclass: #TableView
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'SDS-Tables'!
TableView comment:
'I am the view for table. It creates a SelectionInListView for the table.
See example in the class method to build the table.'!
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
TableView class
instanceVariableNames: ''!
!TableView class methodsFor: 'instance creation'!
openOn: aTable
|topView aSelectionInListView|
topView _ StandardSystemView model: aTable
label: ('Table for: ', aTable valueTitle asString)
minimumSize: 120@300.
topView borderWidth: 1.
aSelectionInListView _ SelectionInListView
on: aTable
printItems: true
oneItem: false
aspect: #currentSelection
change: #currentSelection:
list: #tableOC
menu: #menu
initialSelection: #currentSelection.
topView addSubView: aSelectionInListView in: (0@0 extent:1@1) borderWidth:1.
topView controller open! !
!TableView class methodsFor: 'examples'!
example
"TableView example"
| anOC aTable |
anOC _ OrderedCollection new.
anOC add: 1.0; add: 23.4; add: 234.454.
aTable _ Table
withStartIndex: 0
stopIndex: 10
delta: 5
orderedValues: anOC
indexTitle: #time
valueTitle: #graph.
aTable buildTable.
TableView openOn: aTable! !